#include <cctype>
#include <cstdio>
#include <iostream>

using ll =  long long;

ll n,a,b,ans;

struct ReadLL{
    char c;
    ll n,w;
    ReadLL&operator>>(ll &num)noexcept{
        c=0,n=0,w=1;
        while(!isdigit(c)){
            if(c=='-')w=-1;
            c=getchar();
        }
        while(isdigit(c)){
            n=n*10+c-'0';
            c=getchar();
        }
        num=n*w;
        return *this;
    }
}readll;

// auto &is = std::cin;
auto &is = readll;
auto &os = std::cout;

int main(){
    is>>n;
    for(ll i{0};i!=n;i++){
        is>>b;
        if(b>a){
            ans+=b-a;
        }
        a=b;
    }
    os<<ans<<'\n';
}